﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Avalonia.Controls;

namespace TTEngine.Impl.Avalonia
{
    internal class Impl_Window : TTEngine.IGameWindow
    {
        global::Avalonia.Controls.Window _window;
        public Impl_Window(Window window)
        {
            this._window = window;
        }

   

        public string Title { get => _window.Title; set => _window.Title = value; }

        public bool CanResize => true;

        public bool CanToogleFullScreen => true;

        public bool CanHide => true;

        public bool FullScreen { get => _window.WindowState == global::Avalonia.Controls.WindowState.FullScreen; set => _window.WindowState = global::Avalonia.Controls.WindowState.FullScreen; }

        public int ScreenWidth
        {
            get
            {
                return (int)_window.Screens.Primary.Bounds.Width; ;
            }
        }

        public int ScreenHeight
        {
            get
            {
                return (int)_window.Screens.Primary.Bounds.Height; ;
            }
        }
        public float ScreenScaleRadio
        {
            get
            {
                return (float)_window.Screens.Primary.Scaling;
            }
        }

        public bool IsFrameDebugInit => false;

        public void Close()
        {
            _window.Close();
        }

        public void FrameDebug_EndFrameCapture()
        {
            throw new NotImplementedException();
        }

        public void FrameDebug_OpenApp()
        {
            throw new NotImplementedException();
        }

        public void FrameDebug_Overlay(bool show)
        {
            throw new NotImplementedException();
        }

        public void FrameDebug_StartFrameCapture()
        {
            throw new NotImplementedException();
        }

        public void Hide()
        {
            _window.Hide();
        }

        public bool IsDesktopPlatform()
        {
            return true;
        }

        public void ResizeAndCenter(int w, int h)
        {
            var sw = this.ScreenWidth;
            var sh = this.ScreenHeight;
            SetPos((sw - w) / 2, (sh - h) / 2, w, h);
        }

        public void SetPos(int x, int y, int w, int h)
        {
            _window.Width = w / ScreenScaleRadio;
            _window.Height = h / ScreenScaleRadio;
            _window.Position = new global::Avalonia.PixelPoint(x, y);
            
        }

        public void Show()
        {
            _window.Show();
        }
    }
}
